﻿using System.Collections.Generic;

namespace Framework.MVC.View
{
    public class ViewMgr : Game.SingleGameObject<ViewMgr>
    {
       public class Event
       {
           public static string ADD_VIEW = "ADD_VIEW";
           public static string REMOVE_VIEW = "REMOVE_VIEW";
       }

        private readonly Dictionary<string, ViewBase> m_viewDict = new Dictionary<string, ViewBase>();


        public ViewBase AddView(string name, ViewBase viewObj)
        {
            m_viewDict[name] = viewObj;
            eventObj.Emit(ViewMgr.Event.ADD_VIEW,name);
            return viewObj;
        }

        public bool RemoveView(string name)
        {
            if (this.m_viewDict.TryGetValue(name,out var viewObj))
            {
                this.m_viewDict.Remove(name);
                viewObj.Destroy();
                eventObj.Emit(ViewMgr.Event.REMOVE_VIEW, name);
                return true;
            }

            return false;
        }


    }
}